<%= render partial: '/admin/merchandise/sub_header'%>

<h3>Product: <%= @product.name %></h3>

<div class='float-right large-6' style='color:<%= @product.active ? "#3A3" : "#C33" %>;'>
  <% if @product.active? %>
    <%= link_to 'Make Inactive', admin_merchandise_product_path(@product),
                          :method => :delete,
                          :data => {:confirm => "This will inactivate the product,  Are you sure?"},
                          :class => 'button success float-right' %>
  <% elsif @product.available? %>
    <%= link_to 'Activate', activate_admin_merchandise_product_path(@product),
                              :method => 'PUT',
                              :data => {:confirm => "This will activate the product,  Are you sure?"},
                              :class => 'button alert float-right' %>
  <% else %>
    Not Ready for Production
  <% end %>
</div>

<fieldset>
  <label>Name</label>
  <p><%= @product.name %></p>

  <label>Description (<%= link_to 'edit', edit_admin_merchandise_products_description_path(@product) %>)</label>
  <p><%= raw @product.description %></p>

  <label>Meta Keywords</label>
  <p><%= @product.meta_keywords %></p>

  <label>Meta Description</label>
  <p><%= @product.meta_description %></p>

  <label>Product Type</label>
  <p><%= @product.product_type.name %></p>

  <label>Shipping Category</label>
  <p><%= @product.shipping_category.name %></p>

  <label>Shipping Details</label>
  <table>
    <% rates = @product.shipping_category.shipping_rates %>
    <tr><th><%= link_to 'Shipping Zone', admin_config_shipping_rates_path %></th><th></th></tr>
    <% @shipping_zones.each do |zone| %>
      <tr>
        <td><%= zone.name %></td>
        <td>
          <% product_rates = rates.map { |rate| rate.shipping_method.name if rate.shipping_method.shipping_zone_id == zone.id }.compact %>
          <% if product_rates.empty? %>
            Not Available
          <% else %>
            <%= product_rates.join('</br>').html_safe %>
          <% end %>
        </td>
      </tr>
    <% end %>
  </table>

</fieldset>

<fieldset>
  <legend>Properties</legend>
  <% @product.product_properties.each do |product_prop|  %>
    <label><%= product_prop.property.identifing_name %>:</label>
    <p><%= product_prop.description %></p>
  <% end %>
</fieldset>

<fieldset id="admin-product-properties" class='span-12'>
  <legend>Variants</legend>

  <% if @product.variants.size == 0 %>
    <p>No variants created yet. <%= link_to 'Create some variants?', edit_admin_merchandise_multi_product_variant_path(@product) %></p>
  <% else %>
    <p><%= link_to 'Edit Variants', edit_admin_merchandise_multi_product_variant_path(@product) %></p>
    <table>
        <tr>
          <th>SKU</th>
          <th>Price</th>
          <th>Cost</th>
          <th>Brand</th>
          <th></th>
        </tr>
      </thead>
      <% @product.variants.each do |variant|  %>
        <tr style='<%= 'color:#FFAEB9;' unless variant.active? %>'>
          <td><%= variant.sku %></td>
          <td><%= variant.price %></td>
          <td><%= variant.cost %></td>
          <td><%= variant.brand.try(:name) %></td>
          <td><%= link_to '2', admin_merchandise_product_variant_path(@product, variant) %></td>
        </tr >
      <% end %>
    </table>
  <% end %>
</fieldset>

<fieldset>
  <legend>Images (<%= link_to 'edit', edit_admin_merchandise_images_product_path(@product) %>)</legend>

  <% @product.images.each do |image| %>
    <label><%= image.photo_file_name %></label>
    <%= image_tag image.photo.url(:small) %>
  <% end %>
  <p></p>
</fieldset>

<p style="margin-top: 30px">
  <%= link_to 'All Products', admin_merchandise_products_path(), :class => 'button yellow warning'%>
</p>
